import apis from '../../http/apis/apis'
export default {
    namespaced: true,
    state: {
        salespersonsData: [],
        ByIdData: [],
        CustomerListData: [],
        CustomerListData1: []
    },
    mutations: {
        getSalespersonsData(state, data) {
            state.salespersonsData = data
        },
        getByIdData(state, data) {
            state.ByIdData = data
        },
        getCustomerListData(state, data) {
            state.CustomerListData = data
        },
        getCustomerListData1(state, data) {
            state.CustomerListData1 = data
        }

    },
    actions: {
        //新增销售员
        async addSalespersons(context, result) {
            let data = await apis.salespersons.addSalespersons(result);
            return data
        },
        //获取全部销售员
        async getSalespersons(context) {
            let data = await apis.salespersons.getSalespersons();
            if (data.code) {
                context.commit('getSalespersonsData', data.data)
            }
        },
        //删除销售员数据
        async deleteSalespersons(context, _id) {
            let data = await apis.salespersons.deleteSalespersons({ _id });
            return data
        },
        //修改销售员数据
        async updateSalespersons(context, result) {
            let data = await apis.salespersons.updateSalespersons(result);
            return data
        },
        //查看该销售员负责的客户列表
        async getCustomerList(context) {
            let data = await apis.salespersons.getCustomerList();
            if (data.code) {
                context.commit('getCustomerListData', data.data)
            }
        },
        //查看该销售员负责的客户列表List
        async getCustomerList1(context, result) {
            let data = await apis.salespersons.getCustomerList1({ salespersonsId: result });
            console.log(data);
            context.commit('getCustomerListData1', data.data)
        }
    },
}